package com.dragee.modules.officialWebsite.controller;

import com.dragee.common.PageUtils;
import com.dragee.common.R;
import com.dragee.modules.officialWebsite.entity.GwBaseTrainPicEntity;
import com.dragee.modules.officialWebsite.service.GwBaseTrainPicService;
import com.dragee.modules.sys.entity.FilesEntity;
import com.dragee.utils.UploadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 基地培训列表
 *
 * @author tc
 * @email tc@mail.com
 * @date 2023-07-15 21:34:21
 */
@RestController
@RequestMapping("officialWebsite/gwbasetrainpic")
@Api(tags = "基地培训列表")
public class GwBaseTrainPicController {
    @Autowired
    private GwBaseTrainPicService gwBaseTrainPicService;

    /**
     * 列表
     */
    @GetMapping("list")
    @ApiOperation("基地培训列表列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = gwBaseTrainPicService.queryPage(params);
        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @GetMapping("{id}")
    @ApiOperation("基地培训列表信息")
    public R Xinfo(@PathVariable("id") Long id){
		GwBaseTrainPicEntity record = gwBaseTrainPicService.getById(id);
        FilesEntity files = UploadUtil.getFilesEntity(record.getFileId());
        if (files != null) {
            record.setFileName(files.getFileName());
            record.setFilePath(files.getFilePath());
        }
        return R.ok().put("data", record);
    }

    /**
     * 保存
     */
    @PostMapping("saveOrUpdate")
    @ApiOperation("保存或修改基地培训列表")
    public R saveOrUpdate(@RequestBody GwBaseTrainPicEntity gwBaseTrainPic){
        gwBaseTrainPicService.saveOrUpdate(gwBaseTrainPic);
        return R.ok();
    }


    /**
     * 删除
     */
    @GetMapping("delete-by-id")
    @ApiOperation("基地培训列表删除")
    public R delete( String id){
		gwBaseTrainPicService.removeById(Long.parseLong(id));
        return R.ok();
    }

    @GetMapping("delete-by-ids")
    @ApiOperation("基地培训列表批量删除")
    public R deletes(String ids){
        String[] idArr = ids.split(",");
        Arrays.stream(idArr).forEach(id -> gwBaseTrainPicService.removeById(Long.parseLong(id)));
        return R.ok();
    }



}
